package com.suse.jd_system_server.service.impl;

import com.suse.jd_system_server.annotation.logWeaving;
import com.suse.jd_system_server.dao.UserDao_rp;
import com.suse.jd_system_server.entity.User;
import com.suse.jd_system_server.epmty.Locations;
import com.suse.jd_system_server.service.UserService_rp;
import com.suse.jd_system_server.utils.BaiduMapUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class UserServiceImpl_rp implements UserService_rp {
    @Autowired
    UserDao_rp userDao_rp;
    @Override
    @logWeaving("对用户表的用户名，个性签名，地址进行修改")
    public Integer updateUser(User user) {
        //通过结构化地址获取经纬度
        Locations locations = new Locations();
        if(user.getAddr() !="" && user.getAddr() != null){
            BaiduMapUtil baiduMapUtil = new BaiduMapUtil();
            try {
                locations = baiduMapUtil.getAddressNi(user.getAddr());
            } catch (Exception e) {
                System.out.println("获取经纬度失败");
                throw new RuntimeException(e);
            }
        }
        user.setAddrx(locations.getLng());
        user.setAddry(locations.getLat());

        return userDao_rp.updateUser(user);
    }

    @Override
    public User selectUser(Long userId) {

        return userDao_rp.selectUser(userId);
    }

    @Override
    @logWeaving("对用户表的密码核对操作不同则对密码进行修改")
    public boolean confPWD(Map<String, Object> param) {
        if (userDao_rp.confPWD(param)){
            return false;
        }else {
           userDao_rp.changePWD(param);
           return true;
        }
    }

}
